package view;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.FlowLayout;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.net.URL;

import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.SwingUtilities;

import controller.Heytetrisapplication;
import view.menuelements.MenuButton;
import view.menuelements.Menupanel;

public class Master {

	public static void setStandardpageOptions(JFrame jframe) {
		jframe.setSize(Toolkit.getDefaultToolkit().getScreenSize());
		jframe.setBackground(Color.DARK_GRAY);
		jframe.setLayout(new BorderLayout());
		jframe.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		jframe.setResizable(false);
		jframe.setFocusable(true);
	}

	public static void setPageVisible(final JFrame jframe) {
		jframe.setUndecorated(true);
		jframe.setVisible(true);
	}

	public static void addCloseButton(final JFrame jframe) {
		MenuButton endebutton = new MenuButton("", 45, 40);
		URL ressource = ClassLoader.getSystemResource("Standardblock_2.png");
		endebutton.setIcon(new ImageIcon(ressource));
		Menupanel toppanel = new Menupanel();
		toppanel.setLayout(new FlowLayout(FlowLayout.RIGHT));
		toppanel.add(endebutton);
		jframe.add(toppanel, BorderLayout.NORTH);
		endebutton.addActionListener(new ActionListener() {

			@Override
			public void actionPerformed(ActionEvent e) {
				System.exit(0);

			}
		});
	}

	public static void setPageInvisible(final JFrame jframe) {
		SwingUtilities.invokeLater(new Runnable() {
			public void run() {
				jframe.setVisible(false);
			}
		});
	}

	public static void addBackbutton(final JFrame jframe) {
		MenuButton backbutton = new MenuButton("", 100, 50);
		Menupanel buttons = new Menupanel();
		URL ressource =  ClassLoader.getSystemResource("BACK.png");
		backbutton.setIcon(new ImageIcon(ressource));
		buttons.add(backbutton);
		jframe.add(buttons, BorderLayout.SOUTH);

		backbutton.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent e) {
				Heytetrisapplication.hauptmenupushed();
				Master.setPageInvisible(jframe);
			}
		});

	}

}
